{% load i18n %}
{% load currency_filters %}

<div id="basket_totals">
    <table class="table table-bordered">
        <tbody>
        <tr>
            <th colspan="2"><h4>{% trans "Basket" %}</h4></th>
        </tr>
        {% with offer_discounts=basket.offer_discounts voucher_discounts=basket.grouped_voucher_discounts %}
        {% if offer_discounts or voucher_discounts %}
            {# Basket total will be discounted so we show a before and after version #}
            <tr>
                <td>{% trans "Basket total (before discounts)" %}</td>
                <td class="align-right">{{ basket.total_incl_tax_excl_discounts|currency }}</td>
            </tr>

            {% if offer_discounts %}
                {% for discount in offer_discounts %}
                <tr>
                    <td class="basket-discount"><span class="label label-success">{% trans "Discount" %}</span> {{ discount.name }}
                        {% if discount.description %}
                        <br/><small>{{ discount.description }}</small>
                        {% endif %}
                    </td>
                    <td class="align-right">-{{ discount.discount|currency }}</td>
                </tr>
                {% endfor %}
            {% endif %}

            {% if voucher_discounts %}
                <tr>
                    <th colspan="2"><h4>{% trans "Vouchers" %}</h4></th>
                </tr>
                {% for discount in voucher_discounts %}
                <tr>
                    <td>
                        {{ discount.voucher.name }} ({{ discount.voucher.code }})
                        {% if editable %}
                        <form action="{% url basket:vouchers-remove discount.voucher.id %}" method="POST">
                            {% csrf_token %}
                            <input type="submit" value="{% trans "Remove" %}" class="btn btn-small btn-danger"/>
                        </form>
                        {% endif %}
                    </td>
                    <td>-{{ discount.discount|currency }}</td>
                </tr>
                {% endfor %}
            {% endif %}

            <tr class="success">
                <td>{% trans "Basket total (after discounts)" %}</td>
                <td class="align-right">{{ basket.total_incl_tax|currency }}</td>
            </tr>
        {% else %}
            {# No discounts to basket #}
            <tr class="success">
                <td >{% trans "Basket total" %}</td>
                <td class="align-right">{{ basket.total_incl_tax|currency }}</td>
            </tr>
        {% endif %}
        {% endwith %}

        <!--
        <tr>
            <th>&nbsp;</th>
            <td></td>
        </tr>

        <tr>
            <th colspan="2">
                <h4>{% trans "Shipping" %}</h4>
                {% if shipping_methods|length > 1 and editable %}
                <small>{% trans "Alternative shipping methods can be chosen during checkout" %}</small>
                {% endif %}
            </th>
        </tr>
        {% if not shipping_method.is_discounted %}
            <tr class="success">
                <td>
                    {% trans "Shipping" %} - {{ shipping_method.name }}
                </td>
                <td class="align-right">{{ shipping_method.basket_charge_incl_tax|currency }}</td>
            </tr>
        {% else %}
            {# As shipping is discounted, we break it down into its original charge and a discount #}
            <tr class="success">
                <td>{% trans "Shipping method" %}</td>
                <td class="align-right">{{ shipping_method.name }}</td>
            </tr>
            <tr>
                <td>{% trans "Shipping total (before discounts)" %}</td>
                <td class="align-right">{{ shipping_method.basket_charge_incl_tax_before_discount|currency }}</td>
            </tr>
            <tr>
                {% with discount=shipping_method.get_discount %}
                <td class="basket-discount"><span class="label label-success">{% trans "Discount" %}</span> {{ discount.name }}</td>
                <td class="align-right">-{{ discount.discount|currency }}</td>
                {% endwith %}
            </tr>
            <tr class="success">
                <td>
                    {% trans "Shipping total (after discounts)" %}
                </td>
                <td class="align-right">{{ shipping_method.basket_charge_incl_tax|currency }}</td>
            </tr>
        {% endif %}
        --->
        {% if basket.post_order_actions %}
            <tr>
                <th>&nbsp;</th>
                <td></td>
            </tr>
            <tr>
                <th><h4>{% trans "Post order actions" %}</h4><small>{% trans "These will be applied once your order is placed." %}</small></th>
                <td></td>
            </tr>
            {% for discount in basket.post_order_actions %}
            <tr class="success">
                <td colspan="2">
                    <span class="label label-success">{{ discount.name }}</span><br/>
                    <p>{{ discount.description }}</p>
                </td>
            </tr>
            {% endfor %}
        {% endif %}

        <tr>
            <th>&nbsp;</th>
            <td></td>
        </tr>
        <tr class="success">
            <td><h4>{% trans "Order total" %}</h4></td>
            <td class="align-right"><h3 class="price_color">{{ order_total_incl_tax|currency }}</h3></td>
        </tr>
        </tbody>
    </table>
</div>
